/* pipdelete.c - pipdelete */

#include <xinu.h>
#include <mips.h>

/*------------------------------------------------------------------------
 *  pipdelete  -  Release a pipe, make it free
 *------------------------------------------------------------------------
 */

syscall   pipdelete(
          pipid32         pipid             /* ID of pipe to delete   */
        )
{
        intmask mask;                   /* saved interrupt mask         */
        struct pipent *piptr;		/* ptr to pipe's table entry	*/
	int32 j;			/* used for iteration		*/	

        mask = disable();

        piptr = &piptab[pipid];

        if (isbadpipid(pipid) || (piptr->pistate == PIPE_FREE)) {
                restore(mask);
                return SYSERR;
        }
	
	semdelete(piptr->psem);
	semdelete(piptr->csem);

	for (j = 0; j < PIPE_SIZ; j++) {	/* reset the buffer	*/
                piptr->pipebuffer[j] = ' ';
	}   

        restore(mask);
        return OK;
}

